/**
 * <copyright>
 * </copyright>
 *

 */
package ms.unicorn.language.languagedef.impl;

import ms.unicorn.language.languagedef.LanguagedefPackage;
import ms.unicorn.language.languagedef.ModuleItem;
import ms.unicorn.language.languagedef.XReferenceExpression;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>XReference Expression</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link ms.unicorn.language.languagedef.impl.XReferenceExpressionImpl#getReference <em>Reference</em>}</li>
 *   <li>{@link ms.unicorn.language.languagedef.impl.XReferenceExpressionImpl#isNewInstance <em>New Instance</em>}</li>
 *   <li>{@link ms.unicorn.language.languagedef.impl.XReferenceExpressionImpl#getDefinition <em>Definition</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class XReferenceExpressionImpl extends MinimalEObjectImpl.Container implements XReferenceExpression
{
  /**
   * The cached value of the '{@link #getReference() <em>Reference</em>}' reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getReference()
   * @generated
   * @ordered
   */
  protected ModuleItem reference;

  /**
   * The default value of the '{@link #isNewInstance() <em>New Instance</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isNewInstance()
   * @generated
   * @ordered
   */
  protected static final boolean NEW_INSTANCE_EDEFAULT = false;

  /**
   * The cached value of the '{@link #isNewInstance() <em>New Instance</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isNewInstance()
   * @generated
   * @ordered
   */
  protected boolean newInstance = NEW_INSTANCE_EDEFAULT;

  /**
   * The cached value of the '{@link #getDefinition() <em>Definition</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getDefinition()
   * @generated
   * @ordered
   */
  protected ModuleItem definition;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected XReferenceExpressionImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return LanguagedefPackage.Literals.XREFERENCE_EXPRESSION;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public ModuleItem getReference()
  {
    if (reference != null && reference.eIsProxy())
    {
      InternalEObject oldReference = (InternalEObject)reference;
      reference = (ModuleItem)eResolveProxy(oldReference);
      if (reference != oldReference)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, LanguagedefPackage.XREFERENCE_EXPRESSION__REFERENCE, oldReference, reference));
      }
    }
    return reference;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public ModuleItem basicGetReference()
  {
    return reference;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setReference(ModuleItem newReference)
  {
    ModuleItem oldReference = reference;
    reference = newReference;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, LanguagedefPackage.XREFERENCE_EXPRESSION__REFERENCE, oldReference, reference));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public boolean isNewInstance()
  {
    return newInstance;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setNewInstance(boolean newNewInstance)
  {
    boolean oldNewInstance = newInstance;
    newInstance = newNewInstance;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, LanguagedefPackage.XREFERENCE_EXPRESSION__NEW_INSTANCE, oldNewInstance, newInstance));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public ModuleItem getDefinition()
  {
    return definition;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetDefinition(ModuleItem newDefinition, NotificationChain msgs)
  {
    ModuleItem oldDefinition = definition;
    definition = newDefinition;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, LanguagedefPackage.XREFERENCE_EXPRESSION__DEFINITION, oldDefinition, newDefinition);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setDefinition(ModuleItem newDefinition)
  {
    if (newDefinition != definition)
    {
      NotificationChain msgs = null;
      if (definition != null)
        msgs = ((InternalEObject)definition).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - LanguagedefPackage.XREFERENCE_EXPRESSION__DEFINITION, null, msgs);
      if (newDefinition != null)
        msgs = ((InternalEObject)newDefinition).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - LanguagedefPackage.XREFERENCE_EXPRESSION__DEFINITION, null, msgs);
      msgs = basicSetDefinition(newDefinition, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, LanguagedefPackage.XREFERENCE_EXPRESSION__DEFINITION, newDefinition, newDefinition));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case LanguagedefPackage.XREFERENCE_EXPRESSION__DEFINITION:
        return basicSetDefinition(null, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case LanguagedefPackage.XREFERENCE_EXPRESSION__REFERENCE:
        if (resolve) return getReference();
        return basicGetReference();
      case LanguagedefPackage.XREFERENCE_EXPRESSION__NEW_INSTANCE:
        return isNewInstance();
      case LanguagedefPackage.XREFERENCE_EXPRESSION__DEFINITION:
        return getDefinition();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case LanguagedefPackage.XREFERENCE_EXPRESSION__REFERENCE:
        setReference((ModuleItem)newValue);
        return;
      case LanguagedefPackage.XREFERENCE_EXPRESSION__NEW_INSTANCE:
        setNewInstance((Boolean)newValue);
        return;
      case LanguagedefPackage.XREFERENCE_EXPRESSION__DEFINITION:
        setDefinition((ModuleItem)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case LanguagedefPackage.XREFERENCE_EXPRESSION__REFERENCE:
        setReference((ModuleItem)null);
        return;
      case LanguagedefPackage.XREFERENCE_EXPRESSION__NEW_INSTANCE:
        setNewInstance(NEW_INSTANCE_EDEFAULT);
        return;
      case LanguagedefPackage.XREFERENCE_EXPRESSION__DEFINITION:
        setDefinition((ModuleItem)null);
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case LanguagedefPackage.XREFERENCE_EXPRESSION__REFERENCE:
        return reference != null;
      case LanguagedefPackage.XREFERENCE_EXPRESSION__NEW_INSTANCE:
        return newInstance != NEW_INSTANCE_EDEFAULT;
      case LanguagedefPackage.XREFERENCE_EXPRESSION__DEFINITION:
        return definition != null;
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString()
  {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (newInstance: ");
    result.append(newInstance);
    result.append(')');
    return result.toString();
  }

} //XReferenceExpressionImpl
